POV-Ray : Newsgroups : povray.general : Bad operands : Re: Bad operands Server Time
29 Jul 2024 22:28:12 EDT (-0400)
  Re: Bad operands  
From: clipka
Date: 20 May 2010 04:23:53
Message: <4bf4f199$1@news.povray.org>
Am 20.05.2010 09:11, schrieb Thomas de Groot:
> I do not understand this. The following macro
>
> #macro GammaColort(Color,Gamma)
>    rgbt<pow(Color.red,Gamma), pow(Color.green,Gamma), pow(Color.blue,Gamma),
> Color.transmit>
> #end
>
> gives a parse error: "Bad operands for period operators"
>
> while the following macros work just fine:
>
> #macro GammaColorf(Color,Gamma)
>    rgbf<pow(Color.red,Gamma), pow(Color.green,Gamma), pow(Color.blue,Gamma),
> Color.filter>
> #end
>
> #macro GammaColorft(Color,Gamma)
>    rgbft<pow(Color.red,Gamma), pow(Color.green,Gamma),
> pow(Color.blue,Gamma), Color.filter, Color.transmit>
> #end
>
> Can somebody tell me what I do wrong?

I guess something's fishy about the values you pass into the macros.

For instance, if you call

     GammaColort(<R,G,B,T>,G)

then at the time of the macro invocation POV-Ray has no way of knowing 
that "T" is intended to represent a transmit component; to POV-Ray, 
<R,G,B,T> is just another 4-component vector.

So when POV-Ray parses the GammaColort macro body, it will translate it to:

     rgbt <
         pow(<R,G,B,T>.red,   G),
         pow(<R,G,B,T>.green, G),
         pow(<R,G,B,T>.blue,  G),
         pow(<R,G,B,T>.transmit)
     >

Enter POV-Ray's bivalence regarding colors and vectors: To POV-Ray, 
colors and vectors are just the same - with colors being vectors with up 
to five components, ordered as <red,green,blue,filter,transmit> = 
<x,y,z,t,_unnamed_> (note that "t" here denotes time, /not/ transmit). 
Thus, when you specify "Color.transmit", you're actually accessing the 
5th component of whatever vector expression "Color" happens to be.

But <R,G,B,T> only has 4 components. Duh!


The issue can easily be solved when considering that

     rgbt <A,B,C,D>

is /fully/ equivalent to

     <A,B,C,0,D>

Thus, you actually need only a single macro and use it as follows:

     #macro GammaColor(Color,Gamma)
       rgbft<pow(Color.red,Gamma), pow(Color.green,Gamma),
       pow(Color.blue,Gamma), Color.filter, Color.transmit>
     #end
     ...
     #declare MyColor = GammaColor(rgbt <R,G,B,T>, G);

You can even use constructs like

     #declare MyColor = GammaColor(red R transmit T, G);

because

     red R transmit T

is just another way of writing

     <R,0,0,0,T>


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.